//
// Created by 11510 on 2024/7/8.
//

#ifndef REACTOR_SOCKET_H
#define REACTOR_SOCKET_H

#include "NonCopyable.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <unistd.h>

class Socket : public NonCopyable {
private:
    int _fd;
public:
    Socket() {
        _fd = ::socket(AF_INET, SOCK_STREAM, 0);
        if (_fd < 0) {
            perror("socket");
            return;
        }
    }

    explicit Socket(int fd) : _fd(fd) {}

    ~Socket() {
        close(_fd);
    }

    int getFileDescriptor() const {
        return _fd;
    }


};


#endif //REACTOR_SOCKET_H
